package com.platform.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.platform.dao.AgentDao;
import com.platform.entity.AgentEntity;
import com.platform.service.AgentService;

/**
 * 商品对应规格表值表Service实现类
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2018-10-07 20:51:28
 */
@Service("agentService")
public class AgentServiceImpl implements AgentService {
    @Autowired
    private AgentDao agentDao;

    @Override
    public AgentEntity queryObject(Integer id) {
        return agentDao.queryObject(id);
    }

    @Override
    public List<AgentEntity> queryAgentList(Map<String, Object> map) {
        return agentDao.queryAgentList(map);
    }

    @Override
    public int queryAgentTotal(Map<String, Object> map) {
        return agentDao.queryAgentTotal(map);
    }

    @Override
    public int save(AgentEntity agent) {
        return agentDao.save(agent);
    }

    @Override
    public int update(AgentEntity agent) {
        return agentDao.update(agent);
    }

    @Override
    public int delete(Integer id) {
        return agentDao.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        return agentDao.deleteBatch(ids);
    }

    @Override
    public void rejectApply(Integer[] ids, String certUsername) {
        if(ids != null && ids.length > 0){
            for(Integer id : ids){
                AgentEntity entity = agentDao.queryObject(id);
                entity.setIsCert(-1);
                entity.setCertTime(new Date());
                entity.setCertUsername(certUsername);
                agentDao.update(entity);
            }
        }
    }

    @Override
    public void passApply(Integer[] ids, String certUsername) {
        if(ids != null && ids.length > 0){
            for(Integer id : ids){
                AgentEntity entity = agentDao.queryObject(id);
                entity.setIsCert(1);
                entity.setCertTime(new Date());
                entity.setCertUsername(certUsername);
                agentDao.update(entity);
            }
        }
    }

    @Override
    public List<AgentEntity> queryVendorList(Map<String, Object> map) {
        return agentDao.queryVendorList(map);
    }

    @Override
    public int queryVendorTotal(Map<String, Object> map) {
        return agentDao.queryVendorTotal(map);
    }

    @Override
    public List<AgentEntity> queryExistAgentApply(Long vendorRootDeptId, Long agentRootDeptId){
        return agentDao.queryExistAgentApply(vendorRootDeptId, agentRootDeptId);
    }
}
